package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.Menu;
import com.itheima.manager.UmsMenuManager;
import com.itheima.vo.MenuVo;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UmsMenuController {
    @Autowired
    UmsMenuManager umsMenuManager;

    //树形结构返回所有菜单列表
    @GetMapping("/menu/treeList")
    public R<List<MenuVo>> findTreeList(){
        return umsMenuManager.findTreeList();
    }

    //根据父级菜单id分页查询菜单
    @GetMapping("/menu/list/{parentId}")
    public R<PageBeanVo> findByParentId(@PathVariable Long parentId,
                                        @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                        @RequestParam(value="pageSize",defaultValue = "5")Integer pageSize){
        return umsMenuManager.findByParentId(parentId,pageNum,pageSize);
    }

    //添加菜单
    @PostMapping("/menu/create")
    public R<String> saveMenu(@RequestBody Menu menu){
        return umsMenuManager.saveMenu(menu);
    }

    //根据ID删除后台菜单
    @PostMapping("/menu/delete/{id}")
    public R<String> deleteMenu(@PathVariable Long id){
        return umsMenuManager.deleteMenu(id);
    }

    //修改后台菜单
    @PostMapping("/menu/update/{id}")
    public R<String> updateMenu(@PathVariable Long id,@RequestBody Menu menu){
        return umsMenuManager.updateMenu(menu);
    }

    //修改菜单显示状态
    @PostMapping("/menu/updateHidden/{id}")
    public R<String> updateHidden(@PathVariable Long id,Integer hidden){
        return umsMenuManager.updateHidden(id,hidden);
    }

    //根据id查询菜单
    @GetMapping("/menu/{id}")
    public R<Menu> findById(@PathVariable Long id){
        return umsMenuManager.findById(id);
    }

}
